<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <?php
    // var_dump($_FILES);
    // array(1) { ["file"]=> array(5) { ["name"]=> string(7) "bg9.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(45) "C:\Users\29691\AppData\Local\Temp\php1DFE.tmp" ["error"]=> int(0) ["size"]=> int(1751) } }

    //Array ( [name] => bg9.gif [type] => image/gif [tmp_name] => C:\Users\29691\AppData\Local\Temp\phpDBE3.tmp [error] => 0 [size] => 1751 )
    $allow_pic_type = array('image/gif', 'image/jpeg', 'image/png', 'image/webp');
    print_r($_FILES['file']);
    $filename = $_FILES['file']['name'];
    $filename = str_replace(" ", "", $filename);
    $tmp_name = $_FILES['file']['tmp_name'];
    $dir = dirname(__FILE__) . '\\file\\';
    $error = $_FILES['file']['error'];
    $pic_type = $_FILES['file']['type'];

    if (!in_array($pic_type, $allow_pic_type)) {
        echo '<script>alert("只支持gif,jpg,png,webp格式!");window.location.href = "index.php";</script>';
        die();
    }

    if ($error == 0) {
        move_uploaded_file($tmp_name, $dir . iconv('utf-8', 'gbk', $filename));
        echo '<script>alert("上传成功!");window.location.href = "index.php";</script>';
    } else {
        echo '<script>alert("上传失败!");window.location.href = "index.php";</script>';
    }
    ?>
</body>

</html>